package com.sunfeng.chap2;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * 验证long write(ByteBuffer[] srcs, int offset, int length) 方法时从通道当前位置开始写入的
 */
public class Test5_1 {
    public static void main(String[] args) throws IOException {
        FileOutputStream fileOutputStream = new FileOutputStream(new File("d:\\51.txt"));

        FileChannel fileChannel = fileOutputStream.getChannel();

        ByteBuffer buffer = ByteBuffer.wrap("12345".getBytes());

        ByteBuffer buffer1 = ByteBuffer.wrap("abcde".getBytes());

        ByteBuffer[] byteBuffer = new ByteBuffer[]{buffer, buffer1};
        fileChannel.write(ByteBuffer.wrap("qqqqq".getBytes()));

        fileChannel.position(2);
        // byteBuffer  这里是buffer数组
        fileChannel.write(byteBuffer, 0, 2);
        fileChannel.close();
        fileOutputStream.close();
    }
}
